﻿#region Copyright

// All Material Copyright © 2008-2010 Dynamic Concepts Development Corp., All Rights Reserved
// 
// For further information please contact SoftwareSupport@dynconcepts.com
// 
// Dynamic Concepts Development Corp.  311 W 57th St. Suite #422, New York, NY 10019

#endregion

#region Using References

using System.Collections;
using System.Collections.Generic;

#endregion

namespace DynConDev.CorpLib.CommandLineParser
{
    public class OptionCollection : IEnumerable<Option>
    {
        private readonly List<Option> r_OptionsByIndex = new List<Option>();
        private readonly Dictionary<string, Option> r_OptionsByName = new Dictionary<string, Option>();

        public Option this[int index]
        {
            get { return r_OptionsByIndex[index]; }
        }

        public int Count
        {
            get { return r_OptionsByIndex.Count; }
        }

        public Option this[string name]
        {
            get { return r_OptionsByName[name]; }
        }

        #region IEnumerable<Option> Members

        public IEnumerator<Option> GetEnumerator()
        {
            return r_OptionsByIndex.GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return r_OptionsByIndex.GetEnumerator();
        }

        #endregion

        internal void Append(Option option)
        {
            r_OptionsByName.Add(option.Name, option);
            r_OptionsByIndex.Add(option);
        }

        public bool Contains(string optionName)
        {
            return r_OptionsByName.ContainsKey(optionName);
        }
    }
}